﻿using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Diagnostics;
using System.ComponentModel;
using WPFExcelReport.Helpers;
using System.Windows.Input;
namespace WPFExcelReport
{
    public partial class TBS04
    {
        public TBS04()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VBHSATZ();
            this.DataContext = MV;
            InitializeComponent();
        }
        public override void LOADBYAUF()
        {
            base.LOADBYAUF();
            TBMain.Clear();
            if (ORDERNUM.Length < 22)
                return;
            PM["ART"] = ORDERNUM.Substring(1, 20);
            PM["VAR"] = ORDERNUM.Substring(21, 2);
            SResult = TMV.LOADBYWS(PM);
            MergeData(SResult, true);            
            if (ORDERNUM.Length < 22)
                return;
            if (!IsAuto)
                return;
            if (Counts > 0)
                return;
            PM["ART"] = ORDERNUM.Substring(1, 20);
            PM["VAR"] = ORDERNUM.Substring(21, 2); 
            TMV.CREATEBYWS(PM);
            vwMaster.View.MoveCurrentToFirst();
        }
        public override void OnSave()
        {
            if (!IsSaved)
                return;
            if (dwMaster == null)
                return;
            TMV.UpdateBHSATZ(dwMaster, 0);
            base.OnSave();
        }

    }
}
